  //
//  FunctionMenuViewController.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 15/11/26.
//  Copyright © 2015年 周佳兴. All rights reserved. 111111111
//


#import "FunctionMenuViewController.h"
//#import "FounctionCollectionCell.h"
#import "BusinessMenuViewController.h"
#import "MyButtonMainPage.h"
#import "SetUPViewController.h"
#import "ZCZBarViewController.h"
#import "ZJLoopScrollView.h"
#import "PersonalMissionViewController.h"
#import "MessageAlertViewController.h"
#import "TabBarOccupyingController1.h"
#import "ListsViewController.h"
#import "MJRefresh.h"
#import "JPUSHService.h"
#import "ThingsCollectionViewCell.h"
#import "StuButton.h"

#import "CollectionHeaderView.h"
#import "UIChangeDiffentStyle.h"
#import "UILabel+StringFrame.h"
#import "SDCycleScrollView.h"

#import "GetData.h"

#import "TimeLineViewController.h"
#import "EvaluateViewController.h"
#import "ClassContentController.h"
#import "WebViewController.h"

//#import "SeeingThePDFViewController.h"

#define TimeLine 4//第五个是有时间轴的
#define Evaluate 6//第七个是评价
#define ClassContent 0xabbba//暂时隐藏      //第四个是课堂内容
#define NeedDownload 4//第五个需要下载
#define classNum 3//第七个小班课时总量


#define Second  1//第二个
#define Nine  8//第⑨个
#define First  0//第⑨个

#pragma mark - officeBoard need downLoad
#define OneToOneHomeWork 2
#define OneToNHomeWork 5


static const CGFloat MJDuration = 0.5;
static NSString *ifPop;
@interface FunctionMenuViewController ()<SDCycleScrollViewDelegate>{ 
    
    ZJLoopScrollView *loopView;
    TheTopView       *_topView;
    GetData          *getData;
}

@property(nonatomic,retain)NSDictionary *dic2;
@property(nonatomic,retain)NSMutableArray *menuArr;
@property(nonatomic,retain)NSMutableArray *secondArr;
@property(nonatomic,assign)BOOL isheng;
@property(nonatomic,retain)NSMutableArray *rightItemsArr;

@property(nonatomic,retain)UIView *popView;

@property(nonatomic,retain)UIView *blackBackView;

@property(nonatomic,strong)NSArray *hanpusenArr;
@property(nonatomic,copy)NSString *toSchoolString;
@property(nonatomic,assign)BOOL isSecond;
@property(nonatomic,copy)NSString *UserType;
@property(nonatomic,assign)BOOL isFirst;

@end

@implementation FunctionMenuViewController
//static const CGFloat MJDuration = 0.5;

//周佳兴gggg

-(UIView *)popView{
    UIView *parentView = nil;
    NSArray* windows = [UIApplication sharedApplication].windows;
    UIWindow *window = [windows objectAtIndex:0];
    //keep the first subview
    if(window.subviews.count > 0){
        parentView = [window.subviews lastObject];
    }
    UIView *v =[[UIView alloc]initWithFrame:CGRectMake(0, KHEIGHT, KWIDTH, KHEIGHT)];
    [parentView addSubview:v];
    v.backgroundColor=[UIColor clearColor];
    
    UIView *top = [[UIView alloc]init];
    [v addSubview:top];
    [top mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(43);
        make.right.equalTo(v.mas_right).offset(-43);
        make.centerY.equalTo(v.mas_centerY);
        make.height.equalTo(@(KHEIGHT*0.55));
    }];
    
    top.backgroundColor =[UIColor whiteColor];
    top.layer.cornerRadius = 4.5;
    

    UIButton *del_btn =[[UIButton alloc]init];
    [v addSubview:del_btn];
    [del_btn sizeToFit];
    [del_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(top.mas_top).offset(-20);
        make.right.equalTo(top.mas_right).offset(20);
    }];
    
    [del_btn setBackgroundImage:[UIImage imageNamed:@"edus_Popup_close"] forState:UIControlStateNormal];
    [del_btn addTarget:self action:@selector(deleBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *img =[[UIImageView alloc]init];
    [top addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(top.mas_centerX);
        make.centerY.equalTo(top.mas_top);
        make.height.equalTo(@(68));
        make.width.equalTo(@(68));
    }];
    img.image =[UIImage imageNamed:@"edus_Popup_icon"];
    
    UILabel *title =[[UILabel alloc]init];
    [top addSubview:title];
    [title sizeToFit];
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(top.mas_centerX);
        make.top.equalTo(img.mas_bottom).offset(14);
    }];
    title.text = @"入学须知";
    title.font =[UIFont systemFontOfSize:18];
    title.textColor =[UIColor colorWithHex:0x333333];
    
    UIScrollView *sv =[[UIScrollView alloc]init];
    [top addSubview:sv];
    
    UILabel *la =[[UILabel alloc]init];
    [sv addSubview:la];
    la.backgroundColor =[UIColor clearColor];
    
//    NSString *str = _toSchoolString;
    NSString *str = _toSchoolString;
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
    
    la.attributedText = attrStr;
    
    la.numberOfLines = 0;
    la.font =[UIFont systemFontOfSize:15];
    [la sizeToFit];
    la.textColor =[UIColor colorWithHex:0x858585];
    
    float hh = [la sizeThatFits:CGSizeMake(KWIDTH-114, CGFLOAT_MAX)].height;//动态计算高度
//    CGSize size =[la boundingRectWithSize:CGSizeMake(KWIDTH-114, MAXFLOAT)];
    la.frame = CGRectMake(0, 0, KWIDTH-114, hh);
    [sv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(top.mas_left).offset(14);
        make.right.equalTo(top.mas_right).offset(-14);
        make.top.equalTo(title.mas_bottom).offset(23);
        make.bottom.equalTo(top.mas_bottom).offset(-70);
    }];
    sv.backgroundColor =[UIColor whiteColor];
    sv.bounces = YES;
    sv.contentSize = CGSizeMake(240, hh);
    sv.showsVerticalScrollIndicator = NO;
    sv.bounces = NO;
    
    
    
    UIButton *btn =[[UIButton alloc]init];
    [top addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(103));
        make.centerX.equalTo(top.mas_centerX);
        make.bottom.equalTo(top.mas_bottom).offset(-17);
        make.height.equalTo(@(30));
    }];
    btn.layer.cornerRadius = 4.5;
    
    [btn setTitle:@"我知道了!" forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"edus_Popup_bg"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(popViewReturn:) forControlEvents:UIControlEventTouchUpInside];
    return v;
}

-(void)popViewReturn:(UIButton *)btn{
    [UIView animateWithDuration:0.2 animations:^{
        _popView.frame = CGRectMake(0, KHEIGHT, KWIDTH, KHEIGHT);
        _blackBackView.hidden = YES;
        _blackBackView = nil;
        self.cusTabView.hidden = NO;
    }];
}

-(void)deleBtn:(UIButton *)btn{
    [UIView animateWithDuration:0.2 animations:^{
        _popView.frame = CGRectMake(0, KHEIGHT, KWIDTH, KHEIGHT);
        _blackBackView.hidden = YES;
        _blackBackView = nil;
        self.cusTabView.hidden = NO;
    }];
}

/** 解决viewWillAppear时出现时轮播图卡在一半的问题，在控制器viewWillAppear时调用此方法
 *
 *
 *
 *
 */


-(void)dataRequest2:(NSString *)str{
    
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];// 入学须知 获取
    [parmas setObject:str forKey:@"id"];
    NSString * requestStr = [NSString stringWithFormat:@"%@%@", BASE_URL, SCHOOLINFOID];
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        if(data!=nil&&!error){
            _toSchoolString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                        if(ifPop==nil){
                            //self.cusTabView.hidden = YES;//遮罩隐藏
                            if([getUIStyle() isEqualToString:STYLE0]){
                            }else{
                                [self creatPOPView];
                            }
            
                        }
            
        }else{
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            
        }
        
        
    }];


}
-(void)dataRequest{
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:@"313" forKey:@"tableId"];
    [parmas setObject:@"2782" forKey:@"pageId"];
    NSString * requestStr = [NSString stringWithFormat:@"%@%@", BASE_URL, GOTOSCHOOL];
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        if(data!=nil&&!error){
            
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSArray *arr =[obj objectForKey:@"rows"];
            NSString *str =[NSString stringWithFormat:@"%@",[arr[0] objectForKey:@"AFM_1"]];
            [self dataRequest2:str];
//            if(ifPop==nil){
//                //self.cusTabView.hidden = YES;//遮罩隐藏
//                if([getUIStyle() isEqualToString:STYLE0]){
//                }else{
//                    [self creatPOPView];
//                }
//                
//            }
            
        }else{
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            
        }
        
        
    }];

}

-(void)viewWillAppear:(BOOL)animated{
//    [self.dataArr removeAllObjects];
    NSLog(@"%@",self.dataArr);
    self.UserType = getUserType();
    [self getDocumentData];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    if (userId()) {
        [dic setObject:userId() forKey:@"userId"];
        NSString *requestUrl = [NSString stringWithFormat:@"%@mongoModel_interfacePlcheckMessage.do?",BASE_URL];
        NSUserDefaults *ud1 = [NSUserDefaults standardUserDefaults];
        [NetRequest requestUrl:requestUrl andParamas:dic andReturnBlock:^(NSData *data, NSError *error) {
            if (data&&!error) {
                NSString *str = [[ NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                if ([str isEqualToString:@"0"]) {
                    NSLog(@"+++---失败");
                }else if ([str isEqualToString:@"1"]){
                    NSLog(@"+++---成功");
                    [ud1 setObject:[NSString stringWithFormat:@"%zd",0] forKey:@"badge"];
                    [ud1 synchronize];
                }else if ([str isEqualToString:@"2"]){
                    NSLog(@"+++---没有未读消息");
                    [ud1 setObject:[NSString stringWithFormat:@"%zd",0] forKey:@"badge"];
                    [ud1 synchronize];
                }else{
                    NSLog(@"+++---其他情况");
                }
            }else{
                NSLog(@"网络错误");
            }
        }];
        
    }
    //这里添加头像功能判断
    if (getAvatarUpload()) {

//    if ([getUIStyle() isEqualToString:STYLE0]) {
        if (userIcon()) {
            _imagePath = userIcon();
            if (_imagePath == nil) {
                NSLog(@"需要请求");
                
                
            }else{//本地有头像，可以使用头像
                NSNotification * notice = [NSNotification notificationWithName:@"NeedChangeImageViewImage" object:@"YES" userInfo:nil];
                [[NSNotificationCenter defaultCenter]postNotification:notice];
                //                _headImg.image = [self getLocalIcon];
            }
            
            
        }else{//没有可用头像
            NSNotification * notice = [NSNotification notificationWithName:@"NeedChangeImageViewImage" object:nil userInfo:@{@"HaveIcon":@"NO"}];
            [[NSNotificationCenter defaultCenter]postNotification:notice];
            //            _headImg.image =[UIImage imageNamed:@"my_portrait_normal"];
        }
    }else{
        
    }
    
#pragma mark - 入园须知代码
    
//    if([getUIStyle() isEqualToString:STYLE1]){
//        NSString *isNeedRYXZ = getIsFirstNeedRYXZ();
//        
//        if ([isNeedRYXZ isEqualToString:@"YES"]) {
//            
//        }else{
//            saveIsFirstNeedRYXZ(@"YES");
//            [self dataRequest];
//
//        }
//        
//    }
    
   
    [_topView.cycleScrollView adjustWhenControllerViewWillAppera];
    NSLog(@"hahaqqq2222222qq");
    [super viewWillAppear:YES];
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    
    
//                if(ifPop==nil){
//                    //self.cusTabView.hidden = YES;//遮罩隐藏
//                    if([getUIStyle() isEqualToString:STYLE0]){
//                    }else{
//                        [self creatPOPView];
//                    }
//    
//                }
    
    [noti postNotificationName:@"pan" object:@"canUse"];
    if(loopView)[loopView setContentOfSet];
    self.cusTabView.hidden = NO;
    loopView.autoScroll = YES;

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    NSInteger badge = [[ud objectForKey:@"badge"] integerValue];
    if (!_badgeLabel) {
//        return ;
    }else{
        if (badge>0) {
            _badgeLabel.text = [NSString stringWithFormat:@"%zd",badge];
            _badgeLabel.hidden = NO;
            _borderView.hidden = NO;
        }else{
            _badgeLabel.hidden = YES;
            _borderView.hidden = YES;
        }
        
    }
    //#ifdef Student
    //    if(![getUIStyle() isEqualToString:STYLE0]){
    if (_red) {
        //            NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        //            NSString *badge = [ud objectForKey:@"badge"];
        if (badge>0) {
            _red.hidden = YES;
        }else{
            _red.hidden = YES;
        }
    }
    //    }
    //#endif
    
    
}

-(UIView *)red{
    if (!_red) {
        _red = [[UIView alloc] init];
        _red.backgroundColor = [UIColor redColor];
        _red.layer.cornerRadius = 2.6f;
        
    }
    return _red;
}

-(UIButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = [[UIButton alloc] init];
    }
    return _rightBtn;
}

-(void)viewWillDisappear:(BOOL)animated{
//    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
//    [ud setObject:@"NO" forKey:@"NEEDSV"];
//    [ud synchronize];
    [super viewWillDisappear: animated];
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    [noti postNotificationName:@"pan" object:@"remove"];
    loopView.autoScroll = NO;
    
}

/**
 入学通知弹出视图
 */
-(void)creatPOPView{
    UIView *parentView = nil;
    NSArray* windows = [UIApplication sharedApplication].windows;
    UIWindow *window = [windows objectAtIndex:0];
    //keep the first subview
    if(window.subviews.count > 0){
        parentView = [window.subviews lastObject];
    }
    
    ifPop = @"has poped";
    _blackBackView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    [parentView addSubview:_blackBackView];
    _blackBackView.backgroundColor =[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.2];
    [_blackBackView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(parentView.mas_top).offset(20);
//        make.left.equalTo(parentView.mas_left).offset(20);
//        make.bottom.equalTo(parentView.mas_bottom).offset(-20);
//        make.right.equalTo(parentView.mas_right).offset(-20);
        make.edges.equalTo(parentView);
    }];
    
    _popView =[self popView];
    [UIView animateWithDuration:0.5 animations:^{
        _popView.frame = CGRectMake(0, 0, KWIDTH, KHEIGHT);
    }];
}

#pragma mark - 轮播图点击事件

-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", (long)index);
    
    //    [self.navigationController pushViewController:[NSClassFromString(@"DemoVCWithXib") new] animated:YES];
}


-(void)viewDidLoad{
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    _hanpusenArr = @[@"stu_my_order",@"stu_my_task",@"stu_my_journal",@"stu_my_attendance",@"stu_my_leave",@"stu_my_visit",@"stu_my_achievement",@"stu_my_evaluate",@"stu_my_evaluate_curriculum",@"stu_my_meeting",@"stu_my_report"];
    
    getData = [[GetData alloc]init];
    
    //*** top loop
    _topView = [[TheTopView alloc]init];
    [self.view addSubview:_topView];
    
    //#ifdef Main
    if([getUIStyle() isEqualToString:STYLE0]){
        [_topView WithStyle:STYLE0 andDelegate:self];
        
        _topView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 134/2);
    }else{
        
        //#else
        [self setTitleLabelText:@"学员端"];
        [_topView WithStyle:STYLE1 andDelegate:self];
        _topView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300/2);
    }
    
    //#endif
    
    //
    
    //    _isheng=YES;
    _dic2= [[NSDictionary alloc]init];
    _menuArr = [[NSMutableArray alloc]init];
    _secondArr = [[NSMutableArray alloc]init];
    self.dataArr = [[NSMutableArray alloc]init];
    
    //*** 设置极光推送 代码
    [self JPushSet];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    
    // 获取 存储的 数据源
    
    [getData getDocumentData:^(NSMutableArray *menuArr, NSMutableArray *secondArr, NSMutableArray *dataArr) {
        
        [self.collectionView.header endRefreshing];

        _menuArr = menuArr;
        _secondArr = secondArr;
        self.dataArr = dataArr;
        [self.collectionView reloadData];
    }];
    //[self getDocumentData];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    
    
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置其边界
    flowLayout.minimumInteritemSpacing = 0;
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) collectionViewLayout:flowLayout];
#pragma mark - 代码分支 --- 主项目代码flowLayout
    //#ifdef Main
    //这里添加了角色判断   暂时不改，消息相关
    if ([getUserType() isEqualToString:UserISHPSTeacher]) {
//    if([getUIStyle() isEqualToString:STYLE0]){
        
        self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.rightBtn.frame = CGRectMake(0, 0, 44/2, 44/2);
        //
        [self.rightBtn setBackgroundImage:[UIImage imageNamed:@"nav_news"] forState:UIControlStateNormal];
        [self.rightBtn addTarget:self action:@selector(RightClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *ritem = [[UIBarButtonItem alloc]initWithCustomView:self.rightBtn];
        self.navigationItem.rightBarButtonItem = ritem;
        
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        NSString *badge = [ud objectForKey:@"badge"];
        NSLog(@"%zd",badge.integerValue);
        
        if (badge.integerValue>0) {
            NSLog(@"有未读消息");
            [self.rightBtn addSubview:self.red];
            [self.red mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.rightBtn.mas_top);
                make.right.equalTo(self.rightBtn.mas_right).offset(2.5);
                make.width.equalTo(@(5));
                make.height.equalTo(@(5));
            }];
        }else{
            NSLog(@"无未读消息");
            
        }
        
        
        
        [flowLayout setItemSize:CGSizeMake([UIScreen mainScreen].bounds.size.width/2, 150/2)];//设置cell的尺寸
        //这里添加了版本判断
        if ([getUIStyle() isEqualToString:STYLE0]) {
            [self setTitleLabelText:@"主项目"];
        }else{
            if([ud valueForKey:PROGRAMANAME])
            {
                [self setTitleLabelText:[userDefault valueForKey:@"Hampson"]];
            }else{
                [self setTitleLabelText:@"Hampson"];
            }
        }

//        if([ud valueForKey:PROGRAMANAME])
//        {
//            [self setTitleLabelText:[userDefault valueForKey:@"Hampson"]];
//        }else{
//            [self setTitleLabelText:@"Hampson"];
//        }
        [flowLayout setMinimumLineSpacing:0];
        [self.collectionView registerClass:[FounctionCollectionCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];//注册必不可少
    }else{
#pragma mark - 代码分支 --- 学员端代码flowLayout
        //#elif Student
        UIButton *leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        leftNavBtn.frame = CGRectMake(0, 0, 44/2, 44/2);
        //形状-16@2x
        leftNavBtn.hidden = YES;//隐藏扫码
        [leftNavBtn setBackgroundImage:[UIImage imageNamed:@"nav_scan_code"] forState:UIControlStateNormal];
        [leftNavBtn addTarget:self action:@selector(LeftClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:leftNavBtn];
        self.navigationItem.leftBarButtonItem = item;
        
        self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.rightBtn.frame = CGRectMake(0, 0, 44/2, 44/2);
        //
        [self.rightBtn setBackgroundImage:[UIImage imageNamed:@"nav_news"] forState:UIControlStateNormal];
        [self.rightBtn addTarget:self action:@selector(RightClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *ritem = [[UIBarButtonItem alloc]initWithCustomView:self.rightBtn];
        self.navigationItem.rightBarButtonItem = ritem;
        
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        NSString *badge = [ud objectForKey:@"badge"];
        NSLog(@"%zd",badge.integerValue);
        
        if (badge.integerValue>0) {
            NSLog(@"有未读消息");
            [self.rightBtn addSubview:self.red];
            [self.red mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.rightBtn.mas_top);
                make.right.equalTo(self.rightBtn.mas_right).offset(2.5);
                make.width.equalTo(@(5));
                make.height.equalTo(@(5));
            }];
        }else{
            NSLog(@"无未读消息");
            
        }
        
        
        
        [flowLayout setItemSize:CGSizeMake([UIScreen mainScreen].bounds.size.width/2, 150/2)];//设置cell的尺寸
        
        //    [self setTitleLabelText:@"学员端"];
        [flowLayout setMinimumLineSpacing:0];
        [self.collectionView registerClass:[FounctionCollectionCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];//注册必不可少
    }
    
    
    
    //其布局很有意思，当你的cell设置大小后，一行多少个cell，由cell的宽度决定
    
    
    
    [self.view addSubview:self.collectionView];
    self.view.backgroundColor = [UIColor colorWithHex:0xffffff];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        //#ifdef Main
        if([getUIStyle() isEqualToString:STYLE0]){
            
            make.top.equalTo(_topView.mas_bottom);
        }else{
            //#else
            make.top.equalTo(_topView.mas_bottom);
        }
        //#endif
        
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom).offset(-50);
    }];
    //    self.topBgView.backgroundColor = [UIColor clearColor];
    
    self.collectionView.backgroundColor = [UIColor clearColor];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    
    self.collectionView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadNewData];
    }];
    
    
}

#pragma mark - Refresh
-(void)loadNewData{
    
    [self.collectionView.header beginRefreshing];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(MJDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        // 刷新表格
        [self loginBtnClick];
        
        // 拿到当前的下拉刷新控件，结束刷新状态
        [self.collectionView.header endRefreshing];
    });
    
}

#pragma mark - 学员端扫码考勤按钮 ---------  扫码考勤按钮
- (void)LeftClick:(UIButton *)sender{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusDenied||authStatus == AVAuthorizationStatusRestricted) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请允许该应用使用相机\n方法：设置->隐私->相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [alert show];
            return ;
        }
    }
    ZCZBarViewController *zvc = [[ZCZBarViewController alloc] initWithBlock:^(NSString * data, BOOL succeed) {
        if(succeed){
            NSString *urlStr = [[NSString alloc]initWithString:data];
            NSLog(@"%@", urlStr);
            
            //                NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
            //                [param setObject:str forKey:@"stuId"];
            
            [NetRequest requestUrl:urlStr andParamas:nil andReturnBlock:^(NSData *data, NSError *error) {
                if(!error&&data!=nil){
                    NSString *str = [[NSString alloc]initWithData:data  encoding:NSUTF8StringEncoding];
                    NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSLog(@"%@", obj);
                    if ([str isEqualToString:@"1"]) {
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:@"考勤成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        alert.delegate = self;
                        [alert show];
                    }else{
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        alert.delegate = self;
                        [alert show];
                    }
                    NSLog(@"sucess!");
                    //                    _sucess = YES;
                }else{
                    
                    NSString *str = [NSString stringWithFormat:@"系统错误！%@",urlStr];
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    alert.delegate = self;
                    [alert show];
                    NSLog(@"%@",error);
                    //                    _sucess = NO;
                }
                
            }];
            //            NSLog(@"%@",erro);
            
        }
        
    }];
    
    [self.navigationController presentViewController:zvc animated:YES completion:^{
        
    }];;
}

#pragma mark - 消息按钮
- (void)RightClick:(UIButton *)sender{
    MessageAlertViewController *mavc = [[MessageAlertViewController alloc] init];
    mavc.tabbarView = self.cusTabView;
    [self.navigationController pushViewController:mavc animated:YES];
}


//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    NSLog(@"aaaaa");
//}


-(void)creatRightNav{
    UIButton *rightNavBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 22, 22)];
    [rightNavBtn addTarget:self action:@selector(rightNavClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightNavBtn];
    [rightNavBtn setBackgroundImage:[UIImage imageNamed:@"nav_news"] forState:UIControlStateNormal];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:rightNavBtn];
    self.navigationItem.rightBarButtonItem = item;
}

-(void)creatLeftNav{
    UIButton *rightNavBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 22, 22)];
    [rightNavBtn addTarget:self action:@selector(rightNavClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightNavBtn];
    [rightNavBtn setBackgroundImage:[UIImage imageNamed:@"nav_scan_code"] forState:UIControlStateNormal];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:rightNavBtn];
    self.navigationItem.leftBarButtonItem = item;
}

-(void)rightNavClick:(UIButton *)btn{
    
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    [noti postNotificationName:@"showLeftView" object:@"show"];
}

#pragma mark - 取出数据源
-(void)getDocumentData{
    NSString *filename=getSaveFile(userName(),LOGINFOUNCTION);   //获取路径
    NSString *path=[filename stringByAppendingPathComponent:LOGINOK];
    
    NSData *dataNow = [NSData dataWithContentsOfFile:path];
    NSDictionary * dic;
    if(dataNow){
        
        dic = [NSJSONSerialization JSONObjectWithData:dataNow options:NSJSONReadingMutableContainers error:nil];  //读取数据
    }
    //    NSLog(@"%@",dic);
    _dic2 = dic;
    
    [self menuTakeDataUse];
    
}
#pragma mark - 取出通配的缓存数据
-(void)menuTakeDataUse{
    
    [_menuArr removeAllObjects];
    NSMutableArray *arr  =[_dic2 objectForKey:@"roleFollowList"];
    [self.dataArr removeAllObjects]; // 数据刷新之前 清空 之前所残留 --- 缓存数据
    [_menuArr removeAllObjects];
    [_secondArr removeAllObjects];
    [self.collectionView.header endRefreshing];
    NSLog(@"%lu",(unsigned long)self.dataArr.count);
    for (NSDictionary *dic in arr) {
        ThingsModel *model = [[ThingsModel alloc]init];
        model = [model initWithDictionary:dic error:nil];
        [self.dataArr addObject:model];
    }
    NSLog(@"%lu",(unsigned long)self.dataArr.count);
    //#ifdef Main
    if([getUIStyle() isEqualToString:STYLE0]){
        
    }else{
        //#elif Student
        // 学员端下情况下 head 需要数据
        NSMutableArray *Menuarr  =[_dic2 objectForKey:@"menuList"];
        NSMutableArray *Menuarr1  =[_dic2 objectForKey:@"menuList"];
        
        for(NSDictionary *dic in Menuarr){
            NSString *str =[NSString stringWithFormat:@"%@", [dic objectForKey:@"parent_menuId"]];
            BOOL is = YES; // 是没有 问题的 是否是父级
            
            for (NSDictionary *dic1 in Menuarr1) {
                NSString *str1 = [NSString stringWithFormat:@"%@", [dic1 objectForKey:@"menuId"]];
                
                if ([str isEqualToString:str1]) {
                    
                    is = NO;
                    
                    continue;
                }
            }
            
            if (is) { // 是否是父级
                
                
                [_menuArr addObject:dic];
                //                break;
            }else{
                [_secondArr addObject:dic];
            }
        }
//        NSDictionary *lastDic = @{@"img":@"椭圆-1-拷贝-2"};
//        [_menuArr addObject:lastDic];
        NSLog(@"%lu",(unsigned long)_menuArr.count);
    }
    // #endif
    [self.collectionView reloadData];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.dataArr.count;
    
    
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

#pragma mark - 新主项目代码
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    UIChangeDiffentStyle *styleCell = [[UIChangeDiffentStyle alloc]init];
    
    ThingsModel *model = self.dataArr[indexPath.row];
    
    
    //#ifdef Main
    
    if([getUIStyle() isEqualToString:STYLE0]){
        
        return [styleCell UIStyle:STYLE0 andCollectionView:collectionView withIndexPath:indexPath andModel:model];
    }else{
        //#else
        return [styleCell UIStyle:STYLE1 andCollectionView:collectionView withIndexPath:indexPath andModel:model];
    }
    //#endif
    
}


//#pragma mark - 代码分支---主项目 cellforrow and didselect
//#ifdef Main
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    ThingsModel *model = [self.dataArr objectAtIndex:indexPath.row];
    
    //#ifdef Main
    
    if([getUIStyle() isEqualToString:STYLE0]){
        //这里添加了角色判断  汉普森定制化事务看板
        NSLog(@"%ld", (long)indexPath.row);
        if ([getUserType() isEqualToString:UserISHPSTeacher]) {
            if(indexPath.row == Second||indexPath.row == Nine||indexPath.row == classNum||indexPath.row == First){
                _isSecond=NO;
            }else{
                _isSecond = NO;
            }
        }else{
            
        }

        
        [self actionStyle0SelectItemModel:model];
        
    }else{
        //#else
        
        if (indexPath.row == OneToOneHomeWork||indexPath.row == OneToNHomeWork) {
            NSLog(@"这里需要下载");
//            return;
            self.index = indexPath;
        }else{
            self.index = nil;
        }
        [self actionStyle1SelectItemModel:model];
        
    }
    //#endif
    
}

#pragma mark - 主项目 点击事件
-(void)actionStyle0SelectItemModel:(ThingsModel *)model{
    NSString *phonePageIdString = [NSString stringWithFormat:@"%@", model.phonePageId];
    
    if (!model.phonePageId||!model.tableId||[phonePageIdString isEqualToString:@"-1"]||[phonePageIdString isEqualToString:@""]) {// 没有 pageId 没有 tableId 未设置穿透 -1 不能跳转
        
        [self showLabelWithText:@"未设置穿透页"];
        return;
    }
    //*** pop Which View
    
    ListsViewController *lv =[[ListsViewController alloc]init];
    lv.fromThings = YES;// 判断是否来自     事物看板页面
//    if ([model.cnName isEqualToString:@"未批改的作业个数"]) {
//    if ([model.cnName isEqualToString:@"Unconfirmed Class Amount"]) {
    
//    //这里添加了角色判断   没用
//    if ([getUserType() isEqualToString:UserISHPSTeacher]) {
//        //汉普森定制的名字
//        if ([model.cnName isEqualToString:@"Unchecked Assignments"]) {
//            NSLog(@"GGGGGGGGG");
//            lv.TeacherNeedDownLoad = YES;
//        }
//    }else{
//        
//    }

    
    
    lv.menuName = model.cnName;
    lv.pageId = [NSString stringWithFormat:@"%@", model.phonePageId];
    lv.tableId = [NSString stringWithFormat:@"%@", model.tableId];
    lv.model = model;
    [self.navigationController pushViewController:lv animated:YES];
    lv.isSecond = _isSecond;
    lv.cusTabView = self.cusTabView;
    
}

#pragma mark - 学员风格 点击事件
-(void)actionStyle1SelectItemModel:(ThingsModel *)model{
    NSString *phonePageIdString = [NSString stringWithFormat:@"%@", model.phonePageId];
    
    if (!model.phonePageId||!model.tableId||[phonePageIdString isEqualToString:@"-1"]) {// 没有 pageId 没有 tableId 未设置穿透 -1 不能跳转
        [self showLabelWithText:@"未设置穿透页"];
        return;
    }
    
    //*** pop Which View
    
    
    ListsViewController *lv =[[ListsViewController alloc]init];
    lv.fromThings = YES;
    
    lv.menuName = model.cnName;
    
    lv.pageId = [NSString stringWithFormat:@"%@", model.phonePageId];
    lv.tableId = [NSString stringWithFormat:@"%@", model.tableId];
    lv.model = model;
    //这里添加了角色判断   不需要修改
    if ([getUserType() isEqualToString:UserISHPSStudent]) {
        if (self.index.row == OneToOneHomeWork||self.index.row == OneToNHomeWork) {
            lv.isNeedDownload = YES;
        }else{
            lv.isNeedDownload = NO;
        }
    }else{
        
    }

    
    
    [self.navigationController pushViewController:lv animated:YES];
    lv.cusTabView = self.cusTabView;
    
}

#pragma mark - 代码分支 --- end
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    
    
    CollectionHeaderView *clHeadView;
    //#ifdef Main
    if([getUIStyle() isEqualToString:STYLE0]){
        
        clHeadView = [[CollectionHeaderView alloc]initWithStyle:STYLE0 andDelegate:self andArr:nil andBlock:^(MenuModel *dic) {
            [self btnClick:nil andData:dic];
        }];
        
        clHeadView.frame = CGRectMake(0, 0, collectionView.frame.size.width, 2+(200+160)/2);
        [collectionView addSubview:clHeadView];
        
        
        return CGSizeMake(collectionView.frame.size.width, 2+(200+160)/2);
    }else{
        //#else
        NSLog(@"%@",_menuArr);
        clHeadView = [[CollectionHeaderView alloc]initWithStyle:STYLE1 andDelegate:self andArr:_menuArr andBlock:^(MenuModel *dic) {
            
        }];
        
        
        clHeadView.frame = CGRectMake(0, 0, collectionView.frame.size.width, 2+(330+10+123)/2);
        [collectionView addSubview:clHeadView];
        return CGSizeMake(collectionView.frame.size.width, 2+(330+10+123)/2);
    }
    //#endif
    
    
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    UIView *footView = [[UIView alloc] init];
    //    footView.backgroundColor = [UIColor purpleColor];
    footView.frame = CGRectMake(0, collectionView.frame.size.height, collectionView.frame.size.width, 60/2);
    [collectionView addSubview:footView];
    //    footView.backgroundColor = [UIColor redColor];
    footView.hidden = YES;
    return CGSizeMake(collectionView.frame.size.width, 60/2);
}
//这个也是最重要的方法 获取Header的 方法。
//- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
//{
//
////    NSString *CellIdentifier = @"header";
//    //从缓存中获取 Headercell
////    HeaderCRView *cell = (HeaderCRView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIdentifier forIndexPath:indexPath];
//    return nil;
//}
#pragma mark - 代码分支 --- 主项目headerview


- (void)nameCellBtnClick:(UIButton *)sender{
    NSLog(@"aaabbc");
}
#pragma mark - 代码分支 --- 其他端headerview Action



#pragma mark - 代码分支 --- end


#pragma mark - 代码分支 --- 按钮点击事件



-(void)btnClick:(MyButtonMainPage *)myBtn andData:(MenuModel *)model{
    NSLog(@"%ld", myBtn.Btntag);
    
    if([getUIStyle() isEqualToString:STYLE0]){
        
        [self seleStyle0CCell:model];
    }else{
        //#else
        
    }

    /**if(myBtn.Btntag == 1){
        PersonalMissionViewController *pmvc = [[PersonalMissionViewController alloc] init];
        pmvc.tabbarView = self.cusTabView;
        [self.navigationController pushViewController:pmvc animated:YES];
    }else if(myBtn.Btntag ==2){
        MessageAlertViewController *mavc = [[MessageAlertViewController alloc] init];
        mavc.tabbarView = self.cusTabView;
        [self.navigationController pushViewController:mavc animated:YES];
    }
    else if(myBtn.Btntag == 3){
        
        SetUPViewController *sv =[[SetUPViewController alloc]init];
        sv.tabbarView = self.cusTabView;
        [self.navigationController pushViewController:sv animated:YES];
    }
#pragma -mark 扫一扫点击事件
    else if (myBtn.Btntag == 0) {
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
            AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
            if (authStatus == AVAuthorizationStatusDenied||authStatus == AVAuthorizationStatusRestricted) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请允许该应用使用相机\n方法：设置->隐私->相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                [alert show];
                return ;
            }
        }
        ZCZBarViewController *zvc = [[ZCZBarViewController alloc] initWithBlock:^(NSString * data, BOOL succeed) {
            if(succeed){
                NSString *urlStr = [[NSString alloc]initWithString:data];
                NSLog(@"%@", urlStr);
                
                [NetRequest requestUrl:urlStr andParamas:nil andReturnBlock:^(NSData *data, NSError *error) {
                    if(!error&&data!=nil){
                        NSString *str = [[NSString alloc]initWithData:data  encoding:NSUTF8StringEncoding];
                        NSString *useStr = [NSString stringWithFormat:@"%@%@",[str componentsSeparatedByString:@",fieldCnName:" ][0],@"}"];
                        NSData *canUseDate = [useStr dataUsingEncoding:NSUTF8StringEncoding];
                        NSLog(@"%@",useStr);
                        NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:canUseDate options:NSJSONReadingMutableContainers error:nil];
                        NSLog(@"%@", obj);
                        if ([str isEqualToString:@"1"]) {
                            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:@"考勤成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                            alert.delegate = self;
                            [alert show];
                        }else{
                            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                            alert.delegate = self;
                            [alert show];
                        }
                        NSLog(@"sucess!");
                        _sucess = YES;
                    }else{
                        NSLog(@"%@",error);
                        _sucess = NO;
                    }
                    
                }];
                //            NSLog(@"%@",erro);
                
            }
            
        }];
        
        [self.navigationController presentViewController:zvc animated:YES completion:^{
            
        }];;
    }
     */
}

#pragma mark - 主项目风格相应事件
-(void)seleStyle0CCell:(MenuModel *)model{
    
    NSArray *nextArr = model.meunColl;
    NSLog(@"---->==|%@|==<-----",_secondArr);
    
    NSString *classListStr = [NSString stringWithFormat:@"%@", model.menuPageUrl];
    
    if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
        TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
        
        self.cusTabView.hidden = YES;
        
        
        
        tbOC.model = model;
        
        tbOC.fromPop = YES;
        [self.navigationController pushViewController:tbOC animated:YES];
        return;
    }
    if (nextArr.count > 0) {
        ListsViewController *lv =[[ListsViewController alloc]init];
        NSDictionary *oneDic =[nextArr objectAtIndex:0];
        lv.pageId = [oneDic valueForKey:@"pageId"];
        lv.tableId = [oneDic valueForKey:@"tableId"];
        lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
        lv.cusTabView = self.cusTabView;
        lv.menuName = model.menuName;
        
        [self.navigationController pushViewController:lv animated:YES];
        
        
    }else{
        ListsViewController *lv =[[ListsViewController alloc]init];
        lv.pageId = model.pageId;
        lv.tableId = model.tableId;
        lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
        lv.cusTabView = self.cusTabView;
        lv.menuName = model.menuName;
        
        [self.navigationController pushViewController:lv animated:YES];
    }
    
    
    
}

#pragma mark - 代码分支 --- 学员端按钮点击事件

-(void)StuBtnClick:(StuButton *)myBtn{
    
    
    NSLog(@"%zd",myBtn.Btntag);
    
    if (myBtn.Btntag == 7) {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"changeTabbar" object:[NSNumber numberWithInteger:1]];
        //        self.tabBarController.selectedIndex = 1;
        NSLog(@"这里跳转到tabbar第二栏");
        
        
        return;
    }
    

    
    
    if (_menuArr.count-1 <myBtn.Btntag) {
        return ;
    }
    NSDictionary *dic = [_menuArr objectAtIndex:myBtn.Btntag];
    NSMutableArray *nextArr = [[NSMutableArray alloc]init];
    //    for (NSDictionary *dica in _secondArr) {
    //        if ([[NSString stringWithFormat:@"%@", [dica valueForKey:@"parent_menuId"]] isEqualToString:[NSString stringWithFormat:@"%@", [dic valueForKey:@"menuId"]]]) {
    //            [nextArr addObject:dica];
    //        }
    //    }
    
    NSString *anyWay = [NSString stringWithFormat:@"%@",[dic objectForKey:@"actionWay"]];
    
    //    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"alert" message:[NSString stringWithFormat:@"anyway=%@menuurl=%@", [dic objectForKey:@"actionWay"], [dic objectForKey:@"menuPageUrl"]] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    //
    //    [alert show];
    if([anyWay isEqualToString:@"1"]||[dic objectForKey:@"menuPageUrl"]){
        WebViewController *web =[[WebViewController alloc]init];
        web.cusTabView = self.cusTabView;
        [self.navigationController pushViewController:web animated:YES];
        web.menu_Url = [NSString stringWithFormat:@"%@", [dic objectForKey:@"menuPageUrl"]];
        
    }else{
        if([dic valueForKey:@"meunColl"]){
            
            nextArr= [[NSMutableArray alloc]initWithArray:[dic valueForKey:@"meunColl"]];
        }else{
            [nextArr addObject:dic];
        }
        //*** pop Which View
        if(nextArr.count>0){
            
            //这里添加功能判断
            //        if (getTimeLineModel()) {
            if (myBtn.Btntag == TimeLine) {
                //这里添加功能判断
                if (getTimeLineModel()) {
                    NSLog(@"有时间轴");
                    TimeLineViewController *tl =[[TimeLineViewController alloc]init];
                    tl.isTimeLine = YES;
                    NSDictionary *oneDic =[nextArr objectAtIndex:0];
                    
                    NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
                    if ([menuDic objectForKey:@"menuName"]) {
                        tl.menuName = [menuDic objectForKey:@"menuName"];
                    }
                    
                    tl.pageId = [oneDic valueForKey:@"pageId"];
                    tl.tableId = [oneDic valueForKey:@"tableId"];
                    
                    tl.cusTabView = self.cusTabView;
                    tl.menu_url =[_dic2 objectForKey:@"timeInterface"];
                    tl.allArr = [NSMutableArray arrayWithArray:_secondArr];
                    tl.secondArr = [NSMutableArray arrayWithArray:nextArr];
                    
                    
                    
                    [self.navigationController pushViewController:tl animated:YES];
                }else{
                    NSLog(@"学员端程序");
                    NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
                    if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
                        TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
                        
                        self.cusTabView.hidden = YES;
                        
                        tbOC.dataDic = dic;
                        tbOC.fromPop = YES;
                        [self.navigationController pushViewController:tbOC animated:YES];
                        return;
                    }
                    
                    ListsViewController *lv =[[ListsViewController alloc]init];
                    NSDictionary *oneDic =[nextArr objectAtIndex:0];
                    
                    NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
                    if ([menuDic objectForKey:@"menuName"]) {
                        lv.menuName = [menuDic objectForKey:@"menuName"];
                    }
                    
                    
                    lv.pageId = [oneDic valueForKey:@"pageId"];
                    lv.tableId = [oneDic valueForKey:@"tableId"];
                    if (myBtn.Btntag == NeedDownload) {
                        lv.isNeedDownload = YES;
                    }else{
                        lv.isNeedDownload = NO;
                    }
                    
                    [self.navigationController pushViewController:lv animated:YES];
                    lv.cusTabView = self.cusTabView;
                    lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                    lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                    lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                    
                }
                
                
            }else if (myBtn.Btntag == Evaluate){
                //这里添加功能判断
                if (getEvalutionModel()) {
                    NSLog(@"评价");
                    EvaluateViewController *evaView =[[EvaluateViewController alloc]init];
                    evaView.isTimeLine = NO;
                    NSDictionary *oneDic =[nextArr objectAtIndex:0];
                    
                    NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
                    if ([menuDic objectForKey:@"menuName"]) {
                        evaView.menuName = [menuDic objectForKey:@"menuName"];
                    }
                    evaView.pageId = [oneDic valueForKey:@"pageId"];
                    evaView.tableId = [oneDic valueForKey:@"tableId"];
                    
                    evaView.cusTabView = self.cusTabView;
                    evaView.menu_url =[_dic2 objectForKey:@"timeInterface"];
                    evaView.allArr = [NSMutableArray arrayWithArray:_secondArr];
                    evaView.secondArr = [NSMutableArray arrayWithArray:nextArr];
                    
                    
                    
                    [self.navigationController pushViewController:evaView animated:YES];
                }else{
                    NSLog(@"学员端程序");
                    NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
                    if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
                        TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
                        
                        self.cusTabView.hidden = YES;
                        
                        tbOC.dataDic = dic;
                        tbOC.fromPop = YES;
                        [self.navigationController pushViewController:tbOC animated:YES];
                        return;
                    }
                    
                    ListsViewController *lv =[[ListsViewController alloc]init];
                    NSDictionary *oneDic =[nextArr objectAtIndex:0];
                    
                    NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
                    if ([menuDic objectForKey:@"menuName"]) {
                        lv.menuName = [menuDic objectForKey:@"menuName"];
                    }
                    
                    
                    lv.pageId = [oneDic valueForKey:@"pageId"];
                    lv.tableId = [oneDic valueForKey:@"tableId"];
                    if (myBtn.Btntag == NeedDownload) {
                        lv.isNeedDownload = YES;
                    }else{
                        lv.isNeedDownload = NO;
                    }
                    
                    [self.navigationController pushViewController:lv animated:YES];
                    lv.cusTabView = self.cusTabView;
                    lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                    lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                    lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                    
                }
            }
            
            else{
                NSLog(@"学员端程序");
                NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
                if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
                    TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
                    
                    self.cusTabView.hidden = YES;
                    
                    tbOC.dataDic = dic;
                    tbOC.fromPop = YES;
                    [self.navigationController pushViewController:tbOC animated:YES];
                    return;
                }
                
                ListsViewController *lv =[[ListsViewController alloc]init];
                NSDictionary *oneDic =[nextArr objectAtIndex:0];
                
                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
                if ([menuDic objectForKey:@"menuName"]) {
                    lv.menuName = [menuDic objectForKey:@"menuName"];
                }
                
                
                lv.pageId = [oneDic valueForKey:@"pageId"];
                lv.tableId = [oneDic valueForKey:@"tableId"];
                if (myBtn.Btntag == NeedDownload) {
                    lv.isNeedDownload = YES;
                }else{
                    lv.isNeedDownload = NO;
                }
                
                [self.navigationController pushViewController:lv animated:YES];
                lv.cusTabView = self.cusTabView;
                lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            }
            //        }else if(getEvalutionModel()){
            //            if(myBtn.Btntag == Evaluate){
            //
            //                NSLog(@"评价");
            //                EvaluateViewController *evaView =[[EvaluateViewController alloc]init];
            //                evaView.isTimeLine = NO;
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    evaView.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //                evaView.pageId = [oneDic valueForKey:@"pageId"];
            //                evaView.tableId = [oneDic valueForKey:@"tableId"];
            //
            //                evaView.cusTabView = self.cusTabView;
            //                evaView.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                evaView.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                evaView.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //
            //
            //
            //                [self.navigationController pushViewController:evaView animated:YES];
            //            }else{
            //                NSLog(@"学员端程序");
            //                NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
            //                if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
            //                    TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
            //
            //                    self.cusTabView.hidden = YES;
            //
            //                    tbOC.dataDic = dic;
            //                    tbOC.fromPop = YES;
            //                    [self.navigationController pushViewController:tbOC animated:YES];
            //                    return;
            //                }
            //
            //                ListsViewController *lv =[[ListsViewController alloc]init];
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    lv.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //
            //
            //                lv.pageId = [oneDic valueForKey:@"pageId"];
            //                lv.tableId = [oneDic valueForKey:@"tableId"];
            //                if (myBtn.Btntag == NeedDownload) {
            //                    lv.isNeedDownload = YES;
            //                }else{
            //                    lv.isNeedDownload = NO;
            //                }
            //
            //                [self.navigationController pushViewController:lv animated:YES];
            //                lv.cusTabView = self.cusTabView;
            //                lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //
            //            }
            //        }else if ([_UserType isEqualToString:UserISHPSStudent]) {
            //            if (myBtn.Btntag == TimeLine) {
            //                NSLog(@"有时间轴");
            //                TimeLineViewController *tl =[[TimeLineViewController alloc]init];
            //                tl.isTimeLine = YES;
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    tl.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //
            //                tl.pageId = [oneDic valueForKey:@"pageId"];
            //                tl.tableId = [oneDic valueForKey:@"tableId"];
            //
            //                tl.cusTabView = self.cusTabView;
            //                tl.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                tl.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                tl.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //
            //
            //
            //                [self.navigationController pushViewController:tl animated:YES];
            //            }else if(myBtn.Btntag == Evaluate){
            //
            //                NSLog(@"评价");
            //                EvaluateViewController *evaView =[[EvaluateViewController alloc]init];
            //                evaView.isTimeLine = NO;
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    evaView.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //                evaView.pageId = [oneDic valueForKey:@"pageId"];
            //                evaView.tableId = [oneDic valueForKey:@"tableId"];
            //
            //                evaView.cusTabView = self.cusTabView;
            //                evaView.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                evaView.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                evaView.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //
            //
            //
            //                [self.navigationController pushViewController:evaView animated:YES];
            //            }else if (myBtn.Btntag == ClassContent){
            //                ClassContentController *classv =[[ClassContentController alloc]init];
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    classv.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //                classv.pageId = [oneDic valueForKey:@"pageId"];
            //                classv.tableId = [oneDic valueForKey:@"tableId"];
            //
            //                classv.cusTabView = self.cusTabView;
            //                classv.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                classv.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                classv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //                [self.navigationController pushViewController:classv animated:YES];
            //
            //            }else{
            //                NSLog(@"学员端程序");
            //                NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
            //                if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
            //                    TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
            //
            //                    self.cusTabView.hidden = YES;
            //
            //                    tbOC.dataDic = dic;
            //                    tbOC.fromPop = YES;
            //                    [self.navigationController pushViewController:tbOC animated:YES];
            //                    return;
            //                }
            //
            //                ListsViewController *lv =[[ListsViewController alloc]init];
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    lv.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //
            //
            //                lv.pageId = [oneDic valueForKey:@"pageId"];
            //                lv.tableId = [oneDic valueForKey:@"tableId"];
            //                if (myBtn.Btntag == NeedDownload) {
            //                    lv.isNeedDownload = YES;
            //                }else{
            //                    lv.isNeedDownload = NO;
            //                }
            //
            //                [self.navigationController pushViewController:lv animated:YES];
            //                lv.cusTabView = self.cusTabView;
            //                lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //
            //            }
            //        }else{
            //            NSLog(@"学员端程序");
            //            NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
            //            if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
            //                TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
            //
            //                self.cusTabView.hidden = YES;
            //
            //                tbOC.dataDic = dic;
            //                tbOC.fromPop = YES;
            //                [self.navigationController pushViewController:tbOC animated:YES];
            //                return;
            //            }
            //
            //            ListsViewController *lv =[[ListsViewController alloc]init];
            //            NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //            NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //            if ([menuDic objectForKey:@"menuName"]) {
            //                lv.menuName = [menuDic objectForKey:@"menuName"];
            //            }
            //
            //
            //            lv.pageId = [oneDic valueForKey:@"pageId"];
            //            lv.tableId = [oneDic valueForKey:@"tableId"];
            //            //            if (myBtn.Btntag == NeedDownload) {
            //            //                lv.isNeedDownload = YES;
            //            //            }else{
            //            //                lv.isNeedDownload = NO;
            //            //            }
            //
            //            [self.navigationController pushViewController:lv animated:YES];
            //            lv.cusTabView = self.cusTabView;
            //            lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //            lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //            lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //        }
            //        //这里添加了角色判断  暂时无用
            //        if ([_UserType isEqualToString:UserISHPSStudent]) {
            //            if (myBtn.Btntag == TimeLine) {
            //                NSLog(@"有时间轴");
            //                TimeLineViewController *tl =[[TimeLineViewController alloc]init];
            //                tl.isTimeLine = YES;
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    tl.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //
            //                tl.pageId = [oneDic valueForKey:@"pageId"];
            //                tl.tableId = [oneDic valueForKey:@"tableId"];
            //
            //                tl.cusTabView = self.cusTabView;
            //                tl.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                tl.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                tl.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //
            //
            //
            //                [self.navigationController pushViewController:tl animated:YES];
            //            }else if(myBtn.Btntag == Evaluate){
            //
            //                NSLog(@"评价");
            //                EvaluateViewController *evaView =[[EvaluateViewController alloc]init];
            //                evaView.isTimeLine = NO;
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    evaView.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //                evaView.pageId = [oneDic valueForKey:@"pageId"];
            //                evaView.tableId = [oneDic valueForKey:@"tableId"];
            //
            //                evaView.cusTabView = self.cusTabView;
            //                evaView.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                evaView.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                evaView.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //
            //
            //
            //                [self.navigationController pushViewController:evaView animated:YES];
            //            }else if (myBtn.Btntag == ClassContent){
            //                ClassContentController *classv =[[ClassContentController alloc]init];
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    classv.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //                classv.pageId = [oneDic valueForKey:@"pageId"];
            //                classv.tableId = [oneDic valueForKey:@"tableId"];
            //
            //                classv.cusTabView = self.cusTabView;
            //                classv.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                classv.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                classv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //                [self.navigationController pushViewController:classv animated:YES];
            //
            //            }else{
            //                NSLog(@"学员端程序");
            //                NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
            //                if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
            //                    TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
            //
            //                    self.cusTabView.hidden = YES;
            //
            //                    tbOC.dataDic = dic;
            //                    tbOC.fromPop = YES;
            //                    [self.navigationController pushViewController:tbOC animated:YES];
            //                    return;
            //                }
            //
            //                ListsViewController *lv =[[ListsViewController alloc]init];
            //                NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //
            //                NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //                if ([menuDic objectForKey:@"menuName"]) {
            //                    lv.menuName = [menuDic objectForKey:@"menuName"];
            //                }
            //
            //
            //                lv.pageId = [oneDic valueForKey:@"pageId"];
            //                lv.tableId = [oneDic valueForKey:@"tableId"];
            //                if (myBtn.Btntag == NeedDownload) {
            //                    lv.isNeedDownload = YES;
            //                }else{
            //                    lv.isNeedDownload = NO;
            //                }
            //
            //                [self.navigationController pushViewController:lv animated:YES];
            //                lv.cusTabView = self.cusTabView;
            //                lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //                lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //                lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //                
            //            }
            //        }else{
            //            NSLog(@"学员端程序");
            //            NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
            //            if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
            //                TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
            //                
            //                self.cusTabView.hidden = YES;
            //                
            //                tbOC.dataDic = dic;
            //                tbOC.fromPop = YES;
            //                [self.navigationController pushViewController:tbOC animated:YES];
            //                return;
            //            }
            //            
            //            ListsViewController *lv =[[ListsViewController alloc]init];
            //            NSDictionary *oneDic =[nextArr objectAtIndex:0];
            //            
            //            NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //            if ([menuDic objectForKey:@"menuName"]) {
            //                lv.menuName = [menuDic objectForKey:@"menuName"];
            //            }
            //            
            //            
            //            lv.pageId = [oneDic valueForKey:@"pageId"];
            //            lv.tableId = [oneDic valueForKey:@"tableId"];
            ////            if (myBtn.Btntag == NeedDownload) {
            ////                lv.isNeedDownload = YES;
            ////            }else{
            ////                lv.isNeedDownload = NO;
            ////            }
            //            
            //            [self.navigationController pushViewController:lv animated:YES];
            //            lv.cusTabView = self.cusTabView;
            //            lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
            //            lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
            //            lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
            //        }
            
            
            
            
            
            
        }else{
            
            NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
            if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
                TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
                
                self.cusTabView.hidden = YES;
                
                tbOC.dataDic = dic;
                tbOC.fromPop = YES;
                [self.navigationController pushViewController:tbOC animated:YES];
                return;
            }
            
            ListsViewController *lv =[[ListsViewController alloc]init];
            NSMutableString *menuName = [NSMutableString stringWithFormat:@"%@", [dic objectForKey:@"menuName"]];
            if ([menuName rangeOfString:@"手机端"].location != NSNotFound) {
                [menuName replaceCharactersInRange:[menuName rangeOfString:@"手机端"] withString:@""];
            }
            
            
            //        NSDictionary *menuDic = [_menuArr objectAtIndex:myBtn.Btntag];
            //        if ([menuDic objectForKey:@"menuName"]) {
            //            lv.menuName = [menuDic objectForKey:@"menuName"];
            //        }
            
            //        if (menuName) {
            //            lv.menuName = menuName;
            //        }else{
            //            lv.menuName = @"列表";
            //        }
            
            
            
            lv.pageId = [dic valueForKey:@"pageId"];
            lv.tableId = [dic valueForKey:@"tableId"];
            [self.navigationController pushViewController:lv animated:YES];
            lv.cusTabView = self.cusTabView;
            
        }
 
    }
    
    
    
}


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
    
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    if ([[userDefault valueForKey:@"autoLogin"]isEqualToString:@"autoLoginF"]) {
        [self showLabelWithText:@"自动登录失败"];
    }
    
}




#pragma mark - 极光推送代码设置
-(void)JPushSet{
#pragma mark - jpush begain
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self
                      selector:@selector(networkDidSetup:)
                          name:kJPFNetworkDidSetupNotification
                        object:nil];
    [defaultCenter addObserver:self
                      selector:@selector(networkDidClose:)
                          name:kJPFNetworkDidCloseNotification
                        object:nil];
    [defaultCenter addObserver:self
                      selector:@selector(networkDidRegister:)
                          name:kJPFNetworkDidRegisterNotification
                        object:nil];
    [defaultCenter addObserver:self
                      selector:@selector(networkDidLogin:)
                          name:kJPFNetworkDidLoginNotification
                        object:nil];
    [defaultCenter addObserver:self
                      selector:@selector(networkDidReceiveMessage:)
                          name:kJPFNetworkDidReceiveMessageNotification
                        object:nil];
    [defaultCenter addObserver:self
                      selector:@selector(serviceError:)
                          name:kJPFServiceErrorNotification
                        object:nil];
    
#pragma mark - jpush end
}

//极光推送代理方法
#pragma mark - JpushMethod begain
- (void)networkDidSetup:(NSNotification *)notification {
    //    _netWorkStateLabel.text = @"已连接";
    NSLog(@"已连接");
    //    _netWorkStateLabel.textColor = [UIColor colorWithRed:0.0 / 255
    //                                                   green:122.0 / 255
    //                                                    blue:255.0 / 255
    //                                                   alpha:1];
}

- (void)networkDidClose:(NSNotification *)notification {
    //    _netWorkStateLabel.text = @"未连接。。。";
    NSLog(@"未连接");
    //    _netWorkStateLabel.textColor = [UIColor redColor];
}

- (void)networkDidRegister:(NSNotification *)notification {
    NSLog(@"%@", [notification userInfo]);
    
    NSLog(@"已注册");
}
- (void)networkDidLogin:(NSNotification *)notification {
    
    NSLog(@"已登录");
    
    if ([JPUSHService registrationID]) {
        //        _registrationValueLabel.text = [JPUSHService registrationID];
        NSLog(@"get RegistrationID");
    }
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
    NSDictionary *userInfo = [notification userInfo];
    NSString *title = [userInfo valueForKey:@"title"];
    NSString *content = [userInfo valueForKey:@"content"];
    NSDictionary *extra = [userInfo valueForKey:@"extras"];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    [dateFormatter setDateFormat:DATEFORMATE];
    
    NSString *currentContent = [NSString
                                stringWithFormat:
                                @"收到自定义消息:%@\ntitle:%@\ncontent:%@\nextra:%@\n",
                                [NSDateFormatter localizedStringFromDate:[NSDate date]
                                                               dateStyle:NSDateFormatterNoStyle
                                                               timeStyle:NSDateFormatterMediumStyle],
                                title, content, [self logDic:extra]];
    NSLog(@"%@", currentContent);
   
}
- (NSString *)logDic:(NSDictionary *)dic {
    if (![dic count]) {
        return nil;
    }
    NSString *tempStr1 =
    [[dic description] stringByReplacingOccurrencesOfString:@"\\u"
                                                 withString:@"\\U"];
    NSString *tempStr2 =
    [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
    NSString *tempStr3 =
    [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
    NSString *str =
    [NSPropertyListSerialization propertyListFromData:tempData
                                     mutabilityOption:NSPropertyListImmutable
                                               format:NULL
                                     errorDescription:NULL];
    return str;
}
- (void)serviceError:(NSNotification *)notification {
    NSDictionary *userInfo = [notification userInfo];
    NSString *error = [userInfo valueForKey:@"error"];
    NSLog(@"%@", error);
}




#pragma mark - loginButton click
-(void)loginBtnClick{
    if(self.requeatResultLabel)[self.requeatResultLabel removeFromSuperview];
    
    
    NSString *savedStrUserName = userName();
    NSString *saveStraPassWord = passWord();
    
    
    //*** 为了取出时间戳 之后会做处理以更改取出时间戳的方式
    
    NSLog(@"%@", userName());
    NSString *filename=getSaveFile(savedStrUserName,LOGINFOUNCTION);   //获取路径
    NSString *path=[filename stringByAppendingPathComponent:@"loginOK.plist"];
    
    NSData *dataNow = [NSData dataWithContentsOfFile:path];
    NSDictionary * dic;
    if(dataNow){
        
        dic = [NSJSONSerialization JSONObjectWithData:dataNow options:NSJSONReadingMutableContainers error:nil];  //读取数据
    }
    
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    
    NSString *proID = [userDefault objectForKey:PROID];
    
    //*** 设置传递参数
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:savedStrUserName forKey:@"loginName"];
    [parmas setObject:saveStraPassWord forKey:@"password"];
    [parmas setObject:@"1" forKey:@"source"];
    [parmas setObject:proID forKey:@"proId"];
    
    
    [parmas setObject:@"" forKey:@"alterTime"];
    
    NSString *requestStr =[NSString stringWithFormat:@"%@%@", self.programaUrl, LOGIN_URL];
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        if(!error&&data!=nil){
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
            
            
            if ([obj objectForKey:@"personInfoList"]) {//hideMenuList
                NSArray *hidenArr = [obj objectForKey:@"personInfoList"];
                for (NSDictionary *dic in hidenArr) {
                    NSString *menuNameStr = [dic objectForKey:@"menuName"];
                    NSRange range = [menuNameStr rangeOfString:@"个人资料"];
                    if (range.length>0) {
                        savePersonDic(dic);
                    }
                    NSRange range1 = [menuNameStr rangeOfString:@"教师反馈"];
                    if (range1.length>0) {
                        saveFeedBackDic(dic);
                    }
                }
            }
            
            //*** error message
            NSString * errorStr = [NSString stringWithFormat:@"%@", [obj valueForKey:@"error"]];
            if ([errorStr isEqualToString:@"1"]) {
                [self showLabelWithText:[NSString stringWithFormat:@"%@", [obj valueForKey:@"errorMsg"]]];
                
            }else{
                
                //*** save feed back user message
                saveUserNameDes([[obj objectForKey:@"loginInfo"]objectForKey:@"USERNAME"]);
                saveUserId([[obj objectForKey:@"loginInfo"]objectForKey:@"USERID"]);
                NSString *roleNames =[[obj objectForKey:@"loginInfo"]objectForKey:@"roleNames"];
                
                saveUserDisDes(roleNames);
                //                [userDefault setObject:roleNames forKey:@"roleNames"];
                //                [userDefault synchronize];
                
                
                if([obj valueForKey:@"notMsgCount"]){
                    NSLog(@"notMsgCount:%zd",[[obj valueForKey:@"notMsgCount"] intValue]);
                    NSInteger badge = [[obj valueForKey:@"notMsgCount"] integerValue];
                    NSUserDefaults * ud1 = [NSUserDefaults standardUserDefaults];
                    [ud1 setObject:[NSString stringWithFormat:@"%zd",badge] forKey:@"badge"];
                    [UIApplication sharedApplication].applicationIconBadgeNumber = badge;
                }
                
                
                if([obj valueForKey:@"alterTime"]){
                    
                    [userDefault setObject:[obj valueForKey:@"buttons"] forKey:BUTTON_STRING];
                    [userDefault synchronize];
                    
                    //*** save feed back message
                    NSString *path2= myselfSaveFile(savedStrUserName, LOGINFOUNCTION, @"login.plist");
                    
                    NSString *path3 = [path2 stringByAppendingPathComponent:LOGINOK];
                    
                    BOOL succeed = [data writeToFile:path3 atomically:YES];
                    if (succeed) {
                        NSLog(@"-------------- catch ---- 缓存成功");
                    }else{
                        NSLog(@"%@", @"缓存失败");
                    }
                    //re =
                }
                if([[obj valueForKey:@"loginInfo"] valueForKey:@"USERID"])
                {
                    NSLog(@"%@",[[obj valueForKey:@"loginInfo"] valueForKey:@"USERID"]);
                    NSString *alias = [NSString stringWithFormat:@"%@",[[obj valueForKey:@"loginInfo"] valueForKey:@"USERID"]];
                    NSLog(@"%@",alias);
                    [JPUSHService setTags:nil alias:alias fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
                        NSLog(@"%i",iResCode);
                    }];
                }
                
                //                if (re) {
                NSLog(@"ok");
                
                //*** write success
#pragma -mark 通知中心
//                NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
                saveLoginState(LOGSTATE);
//                [noti postNotificationName:@"login" object:@"loginSuccees"];
                [self getDocumentData];
                
                //*** save succeed the user name password for remember
                NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
                saveLoginState(@"yes");
                [userDefault setObject:@"yes" forKey:@"isLogin"];
                [userDefault setObject:[[obj objectForKey:@"loginInfo"] objectForKey:@"STUID"] forKey:@"STUID"];
                [userDefault synchronize];
                
                
            }
            //            NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
            [userDefault setObject:@"autoLoginS" forKey:@"autoLogin"];
            
        }
        else{
            //*** connect failed find wheather requested the user data if have use it
//            NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
            
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
            [userDefault setObject:@"autoLoginF" forKey:@"autoLogin"];
            [userDefault setValue:@"loging" forKey:@"ifloging"];
            [userDefault synchronize];
            
            //*** 登录失败下仍进入主页 ， 根据需求设置是否需要进入此页面
//            [noti postNotificationName:@"login" object:@"loginSuccees"];
            [self getDocumentData];
            NSString *strE = [NSString stringWithFormat:@"%@", error.localizedDescription];
            
            [self showLabelWithText:strE];
            
        }
        
    }];
    
    
}
#pragma mark - 获取本地头像方法
- (UIImage *)getLocalIcon{
    NSString *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSLog(@"%@",paths);
    NSRange range = [_imagePath rangeOfString:@"Documents"];
    NSRange needRange = NSMakeRange(0, range.location+range.length);
    NSLog(@"%@",_imagePath);
    _imagePath = [_imagePath stringByReplacingCharactersInRange:needRange withString:paths];//每次更换沙盒路径需要重新替换新的路径，否则找不到文件。
    NSLog(@"%@",_imagePath);
    
    UIImage *photoImg = [[UIImage alloc]initWithContentsOfFile:_imagePath];
    return photoImg;
    
}
//- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
//
//
//    NSLog(@"%f", self.view.bounds.size.width);
//
//    self.collectionView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64);
//    [self.collectionView reloadData];
//    [self.view layoutIfNeeded];
//    switch (interfaceOrientation) {
//        case UIInterfaceOrientationPortrait:
//            NSLog(@"%f", self.view.bounds.size.width);
//            //home健在下
//            break;
//        case UIInterfaceOrientationPortraitUpsideDown:
//            NSLog(@"%f", self.view.bounds.size.width);
//            //home健在上
//            break;
//        case UIInterfaceOrientationLandscapeLeft:
//            NSLog(@"%f", self.view.bounds.size.width);
//
//            //home健在左
//            break;
//        case UIInterfaceOrientationLandscapeRight:
//            NSLog(@"%f", self.view.bounds.size.width);
//
//            //home健在右
//
//            //***
//            break;
//        default:
//            break;
//
//    }
//
//
//}

//- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
//    
//    //     _isheng=NO;
//}
#pragma mark - JpushMethod end
#pragma mark - 学员端 代码区


//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return NO;}
//- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{}
//这些都可以知道当前的屏幕状态的

@end
